<template>
  <div>
    <div class="warn-top">
      <h4 style="text-align: left; color: #126bff">请假信息管理</h4>

      <el-form
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="80px"
        style="display: flex; flex-wrap: wrap; margin-top: 10px"
      >
        <el-form-item label="申请人姓名:" prop="name" style="width: 300px">
          <el-input
            v-model="formData.name"
            placeholder="请输入申请人姓名"
            clearable
            style="width: 200px"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="审批状态:" prop="name" style="width: 300px">
          <el-select
            v-model="formData.appltStatus"
            clearable
            placeholder="请选择审批状态"
            style="width: 200px"
            @change="select"
          >
            <el-option
              v-for="item in appltStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请时段:" prop="time">
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '80%' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="small ">
          <el-button @click="resetForm()" id="reset">重置</el-button>
          <el-button
            type="primary"
            @click="submitForm(formData)"
            id="submitForm"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="warn-content" style="width: 100%">
      <!-- <p style="display: flex">
        审批默认通过：
        <el-switch
          style="display: block"
          v-model="value2"
          active-color="#13ce66"
          inactive-color="#FF4444"
          active-text="开启"
          inactive-text="关闭"
          @change="applAll"
        >
        </el-switch>
      </p> -->

      <el-table
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        style="width: 100%; cursor: pointer"
      >
        <el-table-column prop="id" label="序号" width="100"> </el-table-column>
        <!-- <el-table-column prop="name" label="申请人照片"> </el-table-column> -->
        <el-table-column prop="name" label="申请人姓名"> </el-table-column>
        <el-table-column prop="startTime" label="开始时间"> </el-table-column>
        <el-table-column prop="endTime" label="结束时间"> </el-table-column>
        <el-table-column prop="totalTime" label="时长"> </el-table-column>
        <el-table-column prop="status" label="审批状态">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <!-- <el-tag size="medium">{{ scope.row.status }}</el-tag> -->
              <el-tag
                style="color: #126bff; border: 1px #126bff solid"
                v-if="scope.row.status == 0"
                >待审批</el-tag
              >
              <el-tag
                style="color: #1cdc7c; border: 1px #1cdc7c solid"
                v-if="scope.row.status == 1"
                type="success"
                >已通过</el-tag
              >
              <el-tag
                style="color: #ff4444; border: 1px #ff4444 solid"
                v-if="scope.row.status == 2"
                type="danger"
                >未通过</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="time" label="申请时间"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0">
              <el-button
                @click="detailClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >
              <el-button
                style="color: #1cdc7c"
                @click="successClick(scope.row)"
                type="text"
                size="small"
                >通过</el-button
              ><el-button
                style="color: #ff4444"
                @click="failClick(scope.row)"
                type="text"
                size="small"
                >拒绝</el-button
              >
            </div>
            <div v-if="scope.row.status != 0">
              <el-button
                @click="detailClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 2, 4, 8]"
        :page-size="pageSize"
        layout="total, prev, pager, next, sizes"
        :total="tableData.length"
        style="float: right; margin-top: 20px"
      >
      </el-pagination>
    </div>
    <!-- 弹窗 -->
    <div>
      <el-dialog
        title="审批"
        :visible.sync="dialogVisible"
        width="550px"
        style="border-radius: 20px"
      >
        <div style="display: flex; flex-wrap: wrap; text-align: left">
          <div class="upIpfo">
            <p>申请人姓名：{{ detaile.name }}</p>
            <p>开始时间：{{ detaile.startTime }}</p>
          </div>
          <div class="upIpfo">
            <p class="text">结束时间：{{ detaile.endTime }}</p>
            <p>时长：{{ detaile.totalTime }}</p>
          </div>
          <div class="upIpfo">
            <p>请假理由：{{ detaile.reason }}</p>
            <p class="text">
              审批状态：
              <span v-if="detaile.status == 1">
                <el-button style="color: #1cdc7c" type="text" size="small"
                  >已通过</el-button
                >
              </span>
              <span v-if="detaile.status == 0">
                <el-button style="color: #126bff" type="text" size="small"
                  >待审批</el-button
                >
              </span>
              <span v-if="detaile.status == 2">
                <el-button style="color: #ff4444" type="text" size="small"
                  >已拒绝</el-button
                >
              </span>
            </p>
          </div>
          <div class="upIpfo">
            <p>
              申请人照片：
              <span style="vertical-align: text-top">
                <img
                  style="width: 50px; height: 50px"
                  :src="detaile.imgSrc"
                  alt=""
                />
              </span>
            </p>
            <div style="flex: 1">
              <p style="width: 100%">申请时间：{{ detaile.time }}</p>
              <p
                v-if="detaile.status == 0"
                style="
                  width: 100%;
                  text-align: right;
                  padding: 15px;
                  box-sizing: border-box;
                "
              >
                <button class="success" @click="successClick(detaile)">
                  通过
                </button>
                <button class="refuse" @click="failClick(detaile)">拒绝</button>
              </p>
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
export default {
  name: "WARN",
  components: {},
  data() {
    return {
      currentPage4: 4,
      // pages: {
      // 按页数查询数据
      currentPage: 1,
      pageSize: 4,
      value: "",
      // },
      appltStatus: [
        {
          value: "3",
          label: "全部",
        },
        {
          value: "1",
          label: "已通过",
        },
        {
          value: "2",
          label: "未通过",
        },
        {
          value: "0",
          label: "待审核",
        },
      ],
      formData: {
        name: "",
        time: "",
        appltStatus: "",
      },
      detaile: {},
      tableData: [
        {
          id: 1,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          status: "0",
          reason: "家里有事",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 2,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "1",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 3,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "2",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 4,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "1",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 5,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "0",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 6,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "0",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
      ],
      initTableData: [
        {
          id: 1,
          name: "王虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          status: "0",
          reason: "家里有事",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 2,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "1",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 3,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "2",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 4,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "1",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 5,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "0",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
        {
          id: 6,
          name: "王小虎",
          startTime: "2023-02-02 11:00",
          endTime: "2023-02-02 18:00",
          totalTime: "7小时",
          reason: "家里有事",

          status: "0",
          time: "2016-05-02 15:30:56",
          workAddress: "---",
          imgSrc: require("@/assets/logo.png"),
        },
      ],
      datalist: [],
      dialogVisible: false,
      value2: false, // 审批默认通过
    };
  },
  watch: {
    $route(to, from) {
      console.log(to, from);
    },
  },
  created() {
    console.log(666);
    // window.addEventListener
  },
  methods: {
    submitForm(formData) {
      console.log(formData);
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
      this.tableData = this.initTableData;
    },
    detailClick(row) {
      console.log(row);
      this.dialogVisible = true;
      this.detaile = row;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    select(e) {
      console.log(e);
    },
    applAll(e) {
      console.log(e);
      if (e == true) {
        console.log("开启默认通过");
        this.tableData.forEach((e) => {
          console.log(e.status);
          e.status = 1;
        });
      } else {
        console.log("关闭默认通过");
      }
    },
    successClick(e) {
      // 通过审核
      console.log(e.status);
      e.status = 1;
      this.dialogVisible = false;
    },
    failClick(e) {
      // 拒绝
      console.log(e.status);
      e.status = 2;
      this.dialogVisible = false;
    },
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
.warn-top {
  // border: 1px red solid;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.warn-top {
  width: calc(100%);
}
/deep/.el-range-editor--medium .el-range-separator {
  line-height: 21px;
  font-size: 14px;
  position: relative;
  top: 4px;
}
/deep/.el-input__suffix-inner {
  position: relative;
  top: -3px;
}
/deep/ .el-range__icon {
  line-height: 21px;
}
// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
/deep/.el-form-item__label {
  // border: 1px red solid;
  width: 90px !important;
}
.warn-content {
  margin-top: 20px;
  // border: 1px red solid;
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
  overflow: auto;
}

.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
.upIpfo {
  display: flex;
  width: 100%;
  // border: 1px red solid;
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  // border: 1px red solid;
  display: inline-block;
  // background-color: skyblue;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.el-input--medium .el-input__icon {
  line-height: 30px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }
/deep/.el-dialog {
  border-radius: 15px !important;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin-top: 0 !important;
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 0 20px 20px 20px !important;
}

/deep/.el-input--suffix .el-input__inner {
  padding-right: 0px;
}
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
  border-radius: 6px !important;
}
// el-table_1_column_5   el-table__cell
.rowText {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
/deep/.el-switch__label.is-active {
  color: #ff4444;
}
.success {
  margin-right: 15px;
  width: 76px;
  height: 36px;
  background: #1cdc7c;
  border-radius: 10px;
  opacity: 1;
  border: none;
  color: #ffffff;
}
.refuse {
  width: 76px;
  height: 36px;
  background: #ff4444;
  border-radius: 10px;
  opacity: 1;
  border: none;
  color: #ffffff;
}
::v-deep.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px !important;
  height: 21px !important;
  font-size: 16px !important;
  color: #13213b !important;
}
</style>

